<?php

    $page_title = "News | Box";
    include 'includes/header.php';
    include "includes/common.php";

    $q = "SELECT new_id, new_title, new_text, new_pic_loc, UNIX_TIMESTAMP(timestamp) as timestamp1
    FROM news ORDER BY timestamp DESC";

    $result = mysqli_query($db_connect, $q);

    $arrayHolder = array(array());

    while($row = mysqli_fetch_assoc($result)) {
        static $i=0;
        $arrayHolder[$i]['new_id'] = $row['new_id'];
        $arrayHolder[$i]['new_title'] = $row['new_title'];
        $arrayHolder[$i]['new_text'] = $row['new_text'];
        $arrayHolder[$i]['new_pic_loc'] = $row['new_pic_loc'];
        $arrayHolder[$i]['new_post_date'] = date('d.m.Y', $row['timestamp1']);
        $arrayHolder[$i]['new_post_hour'] = date('H:i', $row['timestamp1']);
        $i++;
    }
    //echo '<pre>', print_r($arrayHolder, true), '</pre>';


?>
	<!-- web content -->
	<div id="container_content">
		<div id="news_page">
			<div id="main_news">
				<div id="news_header">
					<h2>Новини</h2>
				</div>
				<div class="main_news_big">
					<a href="the_news.php?new=<?php echo $arrayHolder[0]['new_id']?>">
                        <img src="<?php echo $arrayHolder[0]['new_pic_loc'] ?>" alt="">
                    </a>
					<div class="news_name">
						<h2><?php echo $arrayHolder[0]['new_title'] ?></h2>
					</div>
				</div>
                <div class="main_news_big">
                    <a href="the_news.php?new=<?php echo $arrayHolder[1]['new_id']?>">
                        <img src="<?php echo $arrayHolder[1]['new_pic_loc'] ?>" alt="">
                    </a>
                    <div class="news_name">
                        <h2><?php echo $arrayHolder[1]['new_title'] ?></h2>
                    </div>
			</div>
		</div>
		<div>

            <!-- MINI-NEWS LISTING (ALL NEWS AFTER THE FIRST 2 -->
            <?php
                for ($i=2;$i <= count($arrayHolder)-1;$i++) {
                    if($i>=10) break;
                    echo '<div class="mini_news_container">
                    <a href="the_news.php?new='.$arrayHolder[$i]['new_id'].'">
                    <img src="'.$arrayHolder[$i]['new_pic_loc'].'" alt="">
					<h2>'.$arrayHolder[$i]['new_title'].'</h2>
					<div class="author">
						<span>'.$arrayHolder[$i]['new_post_hour'].'</span> |
						<span>'.$arrayHolder[$i]['new_post_date'].'</span>
					</div>
					<p>'.mb_substr($arrayHolder[$i]['new_text'],0,73).'..</p>
				</div>';
                }
            ?>

		</div>
	</div>
<?php

    include 'includes/footer.php';

?>